import type { DifyRequestBody } from '@/app/api/dify/route';
import { rawFetch } from '@/utils/request';

export const sendDifyRequest = (
  body: DifyRequestBody,
  controller: AbortController
) => {
  const request = async () => {
    try {
      return rawFetch.raw('/api/dify', {
        method: "POST",
        body: JSON.stringify({
          query: body.query || '',
          response_mode: body.response_mode || '',
          user: body.user || 'ruanzhu',
          inputs: body.inputs,
        }),
        signal: controller.signal,
        responseType: 'stream',
      });
    } catch (error) {
      throw error;
    }
  };

  return request;
};
